Object monitoring in code debugging

ABSTRACT

According to example embodiments of the present invention, an object to be monitored is determined, the object being associated with a variable in a code snippet including a plurality of statements. The object is monitored in execution of the plurality of statements. If a plurality of updates of the object are detected in the execution of the plurality of statements, a snapshot associated with each of the updates of the object is created. The snapshot includes a current value of the object and a memory address for the current value of the object.

BACKGROUND

Debugging is a process of finding and removing bugs or defects in acomputer program in order to make the program behave as expected.Debugging involves numerous aspects, including, but not limited to,interactive debugging, control flow, integration testing, log files,monitoring (application or system), memory dumps, profiling, statisticalprocess control, and special design tactics to improve detection whilesimplifying changes. Debugging is often performed by means of softwaretools called “debuggers.” A debugger may be provided by an integrateddevelopment environment (IDE).

The debuggers enable the programmer to debug the program in a variety ofways. For example, the programmer may use the debugger to start, monitoror end the execution of the program, set breakpoints, change values inmemory, and so on. Conventionally the debugger allows the programmer touse a step or single-step mode to go through code lines one by one tocheck values of monitored objects. The monitored objects include, forexample, variables of interest in the program or user definedexpressions in the debugger. Another commonly-used functionalityprovided by the debugger is breakpoint. During execution of a codesegment, the debugger can stop execution of the program at any code linewhere a breakpoint is set. Then the programmer may, for example, checkthe execution results for analysis purposes.

SUMMARY

According to an aspect of the present invention, there is a method thatperforms the following operations (not necessarily in the followingorder): (i) determining an object to be monitored, the object beingassociated with a variable in a code snippet, the code snippet includinga plurality of statements; (ii) monitoring the object during executionof the plurality of statements to detect to a set of updates made to theobject during the execution of the plurality of statements; and (iii)creating a snapshot respectively associated with each of the updates ofthe object, with each snapshot including a current value of the objectand a memory address for the current value of the object.

According to an aspect of the present invention, there is a system thatperforms the following operations (not necessarily in the followingorder): (i) determining an object to be monitored, the object beingassociated with a variable in a code snippet, the code snippet includinga plurality of statements; (ii) monitoring the object during executionof the plurality of statements to detect to a set of updates made to theobject during the execution of the plurality of statements; and (iii)creating a snapshot respectively associated with each of the updates ofthe object, with each snapshot including a current value of the objectand a memory address for the current value of the object.

According to an aspect of the present invention, there is a computerprogram product that performs the following operations (not necessarilyin the following order): (i) determine an object to be monitored, theobject being associated with a variable in a code snippet, the codesnippet including a plurality of statements; (ii) monitor the objectduring execution of the plurality of statements to detect to a set ofupdates made to the object during the execution of the plurality ofstatements; and (iii) create a snapshot respectively associated witheach of the updates of the object, with each snapshot including acurrent value of the object and a memory address for the current valueof the object.

BRIEF DESCRIPTION OF THE DRAWINGS

Through the more detailed description of some embodiments of the presentdisclosure in the accompanying drawings, the above and other objects,features and advantages of the present disclosure will become moreapparent, wherein:

FIG. 1 is a block diagram of an electronic device in which embodimentsof the present invention can be implemented;

FIG. 2 is a flowchart of a method for monitoring updates of a variablein accordance with embodiments of the present invention;

FIG. 3 is an example of a code snippet selected from a code segment inaccordance with embodiments of the present invention;

FIG. 4 is an example of a code segment presenting a relationship offunction call of a variable in accordance with embodiments of thepresent invention;

FIG. 5 is an example of a user interface of a debugger for inputtingexpressions in accordance with embodiments of the present invention;

FIG. 6 is a flowchart of a process for monitoring updates of anexpression in accordance with embodiments of the present invention;

FIG. 7 is a flowchart of a method for monitoring updates of variablesand expressions in accordance with embodiments of the present invention;

FIG. 8 is a block diagram of a system for monitoring updates ofvariables and expressions in accordance with embodiments of the presentinvention;

FIG. 9 is a block diagram illustrating an example of a snapshotcollector included in the system as shown in FIG. 8 in accordance withembodiments of the present invention; and

FIG. 10 is a schematic diagram illustrating presentation of snapshotflows for variables and expressions in accordance with embodiments ofthe present invention.

Throughout the drawings, the same, or similar, reference numeralsrepresent the same, or similar, element.

DETAILED DESCRIPTION

In general, example embodiments of the present invention include amethod, system and computer program product for monitoring variables incode debugging.

According to one embodiment of the present invention, there is provideda computer-implemented method. The method comprises determining anobject to be monitored, the object being associated with a variable in acode snippet. The code snippet includes a plurality of statements. Themethod also comprises monitoring the object in execution of theplurality of statements. The method further comprises creating, inresponse to detecting a plurality of updates of the object in theexecution of the plurality of statements, a snapshot associated witheach of the updates of the object. The snapshot includes a current valueof the object and a memory address for the current value of the object.

According to another embodiment of the present invention, there isprovided a system. The system comprises one or more processors and amemory coupled to at least one of the processors. The system furthercomprises a set of computer program instructions stored in the memoryand executed by at least one of the processors in order to performactions. The actions comprise determining an object to be monitored, theobject being associated with a variable in a code snippet. The codesnippet includes a plurality of statements. The actions also comprisemonitoring the object in execution of the plurality of statements. Theactions further comprise creating, in response to detecting a pluralityof updates of the object in the execution of the plurality ofstatements, a snapshot associated with each of the updates of theobject. The snapshot includes a current value of the object and a memoryaddress for the current value of the object.

According to yet another embodiment of the present invention, there isprovided a computer program product. The computer program productcomprises a computer readable storage medium having program instructionsembodied therewith. The program instructions are executable by a deviceto cause the device to determine an object to be monitored, the objectbeing associated with a variable in a code snippet. The code snippetincludes a plurality of statements. The program instructions also causethe device to monitor the object in execution of the plurality ofstatements. The program instructions further cause the device to create,in response to detecting a plurality of updates of the object in theexecution of the plurality of statements, a snapshot associated witheach of the updates of the object. The snapshot includes a current valueof the object and a memory address for the current value of the object.

It is to be understood that the foregoing examples are not intended toidentify key or essential features of embodiments of the presentinvention, nor is it intended to be used to limit the scope of thepresent invention. Other features of various embodiments of the presentinvention will be described below.

Principles relating to some embodiments of the present disclosure willnow be described with reference to some example embodiments. It is to beunderstood that these embodiments are described only for the purpose ofillustration and help those skilled in the art to understand andimplement the present invention, without suggesting any limitations asto the scope of the invention. The invention described herein can beimplemented in various manners other than the ones describe below.

As used herein, the term “includes” and its variants are to be read asopen terms that mean “includes, but is not limited to.” The term “basedon” is to be read as “based at least in part on.” The term “oneembodiment” and “an embodiment” are to be read as “at least oneembodiment.” The term “another embodiment” is to be read as “at leastone other embodiment.” Other definitions, explicit and implicit, may beincluded below.

Reference is first made to FIG. 1, in which an electronic device orcomputer system/server 12 which is applicable to implement theembodiments of the present invention is shown. Computer system/server 12is only illustrative and is not intended to suggest any limitation as tothe scope of use or functionality of embodiments of the inventiondescribed herein.

As shown in FIG. 1, computer system/server 12 is shown in the form of ageneral-purpose computing device. The components of computersystem/server 12 may include, but are not limited to, one or moreprocessors or processing units 16, a system memory 28, and a bus 18 thatcouples various system components including system memory 28 toprocessor 16.

Bus 18 represents one or more of any of several types of bus structures,including a memory bus or memory controller, a peripheral bus, anaccelerated graphics port, and a processor or local bus using any of avariety of bus architectures. By way of example, and not limitation,such architectures include Industry Standard Architecture (ISA) bus,Micro Channel Architecture (MCA) bus, Enhanced ISA (EISA) bus, VideoElectronics Standards Association (VESA) local bus, and PeripheralComponent Interconnect (PCI) bus.

Computer system/server 12 typically includes a variety of computersystem readable media. Such media may be any available media that isaccessible by computer system/server 12, and it includes both volatileand non-volatile media, removable and non-removable media.

System memory 28 can include computer system readable media in the formof volatile memory, such as random access memory (RAM) 30 and/or cachememory 32. Computer system/server 12 may further include otherremovable/non-removable, volatile/non-volatile computer system storagemedia. By way of example only, storage system 34 can be provided forreading from and writing to a non-removable, non-volatile magnetic media(not shown and typically called a “hard drive”). Although not shown, amagnetic disk drive for reading from and writing to a removable,non-volatile magnetic disk (for example, a “floppy disk”), and anoptical disk drive for reading from or writing to a removable,non-volatile optical disk such as a CD-ROM, DVD-ROM or other opticalmedia can be provided. In such instances, each can be connected to bus18 by one or more data media interfaces. As will be further depicted anddescribed below, memory 28 may include at least one program producthaving a set (for example, at least one) of program modules that areconfigured to carry out the functions of embodiments of the invention.

Program/utility 40, having a set (at least one) of program modules 42,may be stored in memory 28 by way of example, and not limitation, aswell as an operating system, one or more application programs, otherprogram modules, and program data. Each of the operating system, one ormore application programs, other program modules, and program data orsome combination thereof, may include an implementation of a networkingenvironment. Program modules 42 generally carry out the functions and/ormethodologies of embodiments of the invention as described herein.

Computer system/server 12 may also communicate with one or more externaldevices 14 such as a keyboard, a pointing device, a display 24, and thelike. One or more devices that enable a user to interact with computersystem/server 12; and/or any devices (for example, network card, modem,etc.) that enable computer system/server 12 to communicate with one ormore other computing devices. Such communication can occur viainput/output (I/O) interfaces 22. Still yet, computer system/server 12can communicate with one or more networks such as a local area network(LAN), a general wide area network (WAN), and/or a public network (forexample, the Internet) via network adapter 20. As depicted, networkadapter 20 communicates with the other components of computersystem/server 12 via bus 18. It should be understood that although notshown, other hardware and/or software components could be used inconjunction with computer system/server 12. Examples, include, but arenot limited to: microcode, device drivers, redundant processing units,external disk drive arrays, RAID (redundant array of independent disks)systems, tape drives, and data archival storage systems, and the like.

In computer system/server 12, I/O interfaces 22 may support one or moreof various different input devices that can be used to provide input tocomputer system/server 12. For example, the input device(s) may includea user device such keyboard, keypad, touch pad, trackball, and the like.The input device(s) may implement one or more natural user interfacetechniques, such as speech recognition, touch and stylus recognition,recognition of gestures in contact with the input device(s) and adjacentto the input device(s), recognition of air gestures, head and eyetracking, voice and speech recognition, sensing user brain activity, andmachine intelligence.

As described above, conventional debuggers allow a programmer to use asingle-step mode and/or breakpoint to debug the program. In thesingle-step mode, the execution of program stops after each statement,such that the programmer can check the value of a monitored object suchas a variable in the program or an expression in the debugger. Or,alternatively, the programmer may set a breakpoint at a code line wherehe/she wants to check the object value. The execution of the programwill stop once the breakpoint is reached. However, at present, it isdifficult to identify a change flow of the variable or expression inexecution of a given code snippet. That is, given a piece of codeconsisting of a series of statements, the debugging process cannotidentify the change procedure of the monitored variable or expressionamong these statements. The programmer has to manually identify wherethe variable value or the expression value might be changed and set thebreakpoints accordingly.

Embodiments of the present invention deal with the above problem bytracking and recording the change flow of a monitored object during theexecution of the program. Within a given code snippet, the debuggingprocess creates a snapshot for the monitored object each time its valuechanges. The snapshot at least records a current value of the object anda memory address for the value of the object. In this way, after theexecution of the code snippet, all updates of the object can bepresented such that the programmer can easily identify the change flowof the object. In embodiments of the present invention, the monitoredobject may include a variable in the code snippet and/or an expressionbeing inputted in a debugger for debugging the code snippet. Monitoringupdates of a variable and of an expression will be described in moredetail with the following particular description of FIG. 2 and FIG. 6,respectively.

Reference is now made to FIG. 2, which depicts a flowchart of a method200 for monitoring updates of a variable in accordance with embodimentsof the present invention. As shown, the method 200 is entered in step210, where a variable to be monitored in a code snippet is determined.The code snippet is a piece of code in the code segment including aplurality of statements. In execution, some statements may change thevalues of one or more variables and/or the memory addresses thereof.FIG. 3 shows an example code segment 300. A code snippet 310 in the codesegment 300 is a piece of code that is expected to be debugged tomonitor changes of some variables included therein.

In some embodiments, the code snippet may be specified by a user fromthe code segment. For example, the user may specify two monitor pointsat two code lines of the code segment. The statements between the twomonitor points may be determined as a code snippet. The line numbersassociated with the specified two monitor points may be used to identifythe code snippet. In the example of FIG. 3, two monitor points 321 and322 are set at code lines 101 and 113. Thus the statements between themonitor points 321 and 322 constitute the code snippet 310. In somecases where the code segment is written in an object-orientedprogramming language, the code segment may have multiple classes andclass member functions. The class name and/or function name associatedmay be used to identify the code snippet from the code segment.

In some embodiments, the user may expressly specify the variable to bemonitored. For example, the user may input the name of the variable.Alternatively, or in addition, the user may select the variable using apointing device like a mouse and mark the variable as the monitoringtarget. For example, as shown in FIG. 3, a variable “conn” 331 may beselected by the user as a variable to be monitored. Alternatively, or inaddition, the code snippet may be parsed automatically to identify allvariables included in the code snippet. Semantic analysis or any othersuitable approaches may be employed to collect the variables from thecode snippet. If multiple variables are identified, the variables may bepresented to the user, for example, in a list. The user may then selectthe variable to be monitored from among these variables. Alternatively,all the identified variables may be monitored in some examples. It is tobe understood that though only one variable 331 is selected in theexample of FIG. 3, the scope of the invention is not limited thereto. Itis possible to select any number of variables to be monitored.

Updates of a variable are monitored in steps 220 and 230. Particularly,in step 220, update of the variable in execution of the plurality ofstatements is detected. To this end, the statements in the code snippetare executed by the debugger. It would be appreciated that one or morestatements, when being executed, may modify the value of the variable.As used herein, the value of a variable may be an integer, a float, astring, a character or the like, depending on the type of the variable.Alternatively, or in addition, the memory address for the value of thevariable might be changed by one or more statements. The update of thememory address indicates that the current value of the variable isdirected to a new memory address. In this event, the variable value mayor may not change.

In order to detect whether the value and/or the memory address isupdated, at the beginning of the code snippet, for example, at the firstof the two monitor points specified in the code segment, an initialvalue of the variable and an initial memory address for the value arerecorded. In execution of each statement of the code snippet, thecurrent value of the variable may be compared with the previous value todetect if the two values are different. For example, in execution of thefirst statement of the code snippet, the current value of the variableis compared with the initial value. If the value is updated, inexecution of next statement, the value of the variable collected now maybe compared with the previously updated value to check if the variableis updated again. A checksum algorithm may be employed to determinewhether checksums of the two values match or not. If the checksums ofthe two values do not match, it is determined that the variable isupdated. Likewise, the memory address for the value of the variablecollected in execution of the current statement and a previous memoryaddress are compared. For example, checksums of the two memory addressesmay be calculated to detect the update of the variable.

Next, in step 230, in response to detecting a plurality of updates ofthe variable, a snapshot associated with each update of the variable iscreated. That is, if it is detected in step 220 that the variable to bemonitored is given a new value, and/or the value of the variable isdirected to a new memory address in execution of a statement, a newsnapshot is created for the update of the variable. In this way, afterexecution of the statements of the code snippet, if a plurality ofupdates of the variable are detected, multiple snapshots are created forthe respective updates.

A snapshot at least includes a value of the variable and a memoryaddress for the value of the variable. In some embodiments, the snapshotcan be created in an incremental way. That is, if only the value of thevariable is changed, the updated value is recorded and the memoryaddress remains unchanged in the newly created snapshot. Likewise, ifonly the memory address is changed, the previous value and the updatedmemory address are recorded in the new snapshot. If the value of thevariable and the memory address for the value are both detected to beupdated, then the created snapshot may include the updated value and theupdated memory address for the updated value.

In some embodiments, the snapshots created for the detected multipleupdates of the variable may be presented to the programmer, so that theprogrammer can check the flow of continuous changes in the variable. Theprogrammer can easily determine whether the value or memory address ofthe variable is updated as desired. In this way, the code debuggingprocess provides the programmer with a more powerful mechanism forvariable monitoring and tracking.

In addition to the value and the memory address, the snapshot mayfurther include context of the variable. As used herein, the contextrefers to the information that indicates the environment or condition atthe time when the update of the variable is detected. In one embodiment,the context of the variable may include a statement where the update ofthe variable is detected. That is, if the variable is updated inexecution of a particular statement, this statement is recorded in thesnapshot for the updated variable. By means of such information, theprogrammer may identify where the variable is updated by checking thecontext of the snapshot. The statement can be represented by its linenumber(s), for example.

In some instances, the location of the statement cannot uniquelyidentify a plurality of snapshots created for updates of the variable.For example, a variable may be included in a loop function of the codesnippet and its value may be updated in execution of a particularstatement included in the loop. In this case, a new snapshot will becreated each time through the loop. However, the location of theparticular statement where update of the variable is detected may remainthe same in each snapshot. In order to differentiate the plurality ofsnapshots, in one embodiment, the context may include a timestamp foreach snapshot to indicate when the update of the variable is detected.As such, even if the variable is updated in the same statement forseveral times, the user can differentiate the snapshots based on thetimestamps.

Alternatively, or in addition, a statement containing a declaration ofthe variable may be recorded in a snapshot as the context of thevariable. In one example, the location of the declaration, for example,in the form of a line number may be included in the context. As known,different variables may share the same variable name, for example, indifferent naming spaces. In order to avoid confusion in the snapshots,in creating a snapshot, the location of declaration of the variable maybe included in the context of the snapshot.

Instead of or in addition to the above information, the context mayinclude a stack status of the variable. As used herein, a “stack status”refers to the relationship of function calls related to the variable.The stack status may also be used to indicate the environment of thevariable when update of the variable is detected. By way of example, asshown in FIG. 4, a code segment 400 has three functions A, B and C. Inthe code segment 400, the function A calls the function B, and thefunction B in turn calls the function C. The variable V to be monitoredis declared in the function B. The function B and function C bothinclude statements related to the variable V and the two functions areincluded in a code snippet 410 specified by a user. If update of thevariable V is detected in the function C during execution of the codesnippet 410, the relationship of function call related to the functionsA, B and C may be recorded as a stack status and be included in asnapshot established in response to the update. After the function Creturns, update of the variable V will be detected in the function B. Atthis point, the stack status of the variable V recorded in the newsnapshot only indicates the function calls between the functions A andB. In this way, the user may determine the exact statement that changesthe variable value.

Although some example information that can be included in the context ofthe variable are discussed above, it will be appreciated that any othersuitable information that can be used to indicate the environment orconditions of the variable may also be collected and recorded in thecontext of the variable. For example, code debugging of a code snippetis generally performed in a computing environment. Conditions of thecomputing environment at the time a snapshot for a variable is recordedmay be collected and included in the context of the variable. Theconditions of the computing environment may include, but are not limitedto, usage of the CPU and memory in the computing environment. Withinformation such as usage of the CPU and memory included in a snapshotcreated for update of the variable, the user may detect effect of theupdate on consumption of resources of the computing environment.

In some embodiments, after the execution of the statements included inthe code snippet completes, the created snapshots may be presented tothe user. All the snapshots may be presented to the user in a sequenceaccording to the time order. That is, the snapshots may be arranged inthe sequence according to an order in which the corresponding updatesare detected. The timestamps recorded in the snapshots may be used todetermine the order of each of the snapshots. The snapshots may bedisplayed in any other suitable way as well. For example, in oneembodiment, a curve may be presented to indicate the change flow of thevariable values that are recorded in the snapshots. The contentsincluded in the snapshots may also be displayed in a diagram or a table,for example.

Moreover, it is known that in code debugging, one or more expressionsmay be written into a debugger to assist the debugging of a codesnippet. It is to be noted that although an expression may bepartitioned from a code snippet to be debugged, in the context of thisdisclosure, an expression refers to the one written in the debugger.FIG. 5 shows an example user interface 500 of a debugger where the usercan input expressions when debugging the code snippet 310. For example,in the user interface 500, four expressions 510 to 540 have been writtenin the debugger. An expression may include a single variable or functionincluded in the code snippet or an operation between several variablesor functions. For example, the expression 510 includes a variable“FLAG_QUERY” that is included in the code snippet 310 as a variable 335,and one variable “url” 332 in the code snippet 310 is included in theexpression 520. The expression 530 defines an operation between twovariables “user” and “pw”, where two variables are both included in thecode snippet 310 as variables 333 and 334. In addition, variables orfunctions that are not included in the code snippet may also be writteninto the debugger as expressions if the user wants to monitor how thosevariables or functions change during debugging of the code snippet. Inthe example of FIG. 5, the expression 540 defines a function“DriverManager.getDrivers( )” that is not included in the code snippet310.

In execution of each statement of the code snippet, the expressionsincluded in the debugger may also be executed to present correspondingvalues. However, similar to the variables of the code snippet, using a“step” mode and a “breakpoint” of conventional debuggers, only thecurrent values of the expressions can be presented after a statement isexecuted or when a breakpoint is reached. It is difficult to identifychange flows of the expressions in a series of statements of the codesnippet.

FIG. 6 shows a flowchart of a method 600 for monitoring updates of anexpression in accordance with embodiments of the present invention. Asshown, the method 600 is entered in step 610, where an expression to bemonitored is determined in a debugger for debugging a code snippet. Thecode snippet may be specified by the user as discussed above withreference to FIG. 2. In general, the expression to be monitored isassociated with the variable that is determined as to be monitored inthe code snippet. In one embodiment, the expression may include thetarget variable itself. For example, if the variable “user” 333 in thecode snippet 310 of FIG. 3 is the target variable, then the expression530 of FIG. 5 which involves the variable “user” 333 may be determinedas the expression to be monitored. In another embodiment, the variableto be monitored may be related to a function that is included in anexpression. In this case, this expression may also be determined fromthe debugger. As an example, if the function “DriverManager.getDrivers()” defined in the expression 540 has some statements involved operationson the variable “FLAG_QUERY” 335 in the code snippet 310, then theexpression 540 may also be determined as the target expression.

In some embodiments, all expressions included in the debugger may beautomatically recognized. Then the expression that is associated withthe variable to be monitored may be determined from the identifiedexpressions. In some other embodiments, all the identified expressionsmay be presented to the user. The user may then select the expression tobe monitored from among the identified expressions. Alternatively, allthe identified expressions may be monitored in some examples.

Updates of an expression are monitored in steps 620 and 630.Particularly, in step 620, update of the expression in execution of theplurality of statements of the code snippet is detected. As mentionedabove, execution of one or more statements may modify the values ormemory addresses of the variables included in the code snippet. In thiscase, if an expression includes one or more of the updated variables, orincludes one or more functions that are related to the updatedvariables, the value and/or memory address of this expression mayprobably change. Upon detecting a change of the value or the memoryaddress of the expression, it is determined that the expression isupdated. The update of the expression can be detected in a similar wayfor detecting the update of the variable as discussed above and will benot repeated here.

Next, in step 630 of the method 600, in response to detecting aplurality of updates of the expression, a snapshot associated with eachof the updates of the expression is created. That is, if it is detectedin step 620 that the expression is given a new value, and/or the valueof the expression is directed to a new memory address in execution of astatement of the code snippet, a new snapshot is created for the updateof the expression. In this way, after execution of the statements of thecode snippet, if a plurality of updates of the expression are detected,multiple snapshots are created for the respective updates.

Similar to the snapshot for the variable, the snapshot for theexpression may include a current value of the expression and a memoryaddress for the value of the expression. In some embodiments, thesnapshot may further include context of the expression. In oneembodiment, the context of the expression includes a timestampindicating when the update of the expression is detected. The timestampmay be used to identify the order of the corresponding snapshot amongmultiple snapshots recorded for the same expression. Alternatively, orin addition, conditions of the computing environment in which the codedebugging is performed may be collected and included in the context ofthe expression. In some embodiments, the resulting snapshots may bepresented to the programmer, for example, in the time sequence. Thisallows the programmer to check the flow of continuous changes in theexpression.

FIG. 7 shows the flowchart of a process 700 for monitoring updates ofvariables and expressions. In the example shown in FIG. 7, multipletarget variables included in a code snippet under debug and targetexpressions written in a debugger for debugging the code snippet areselected to be monitored. The process 700 is entered in step 702, wherethe initial values and initial memory addresses of the target variablesand expressions are collected before executing the code snippet. Thenthe debugging of the code snippet begins and each of the statements ofthe code snippet may be executed by a debugger. In step 704, a statementof the code snippet is executed. At the very beginning, the firststatement is executed.

In the execution of the current statement, one or more of the targetvariables and expressions may be updated. In order to detect the updateof each of the target variables and expressions, one candidate may beselected from the variables and expressions in step 706. The process 700then proceeds to step 708 to detect whether a value of the candidate anda memory address for the value of the candidate are updated. The currentvalue and memory address of the candidate are compared with the initialvalue and memory address collected in step 702 if no snapshot is createdpreviously. In cases where one or more snapshots have been created forthe candidate in response to previous updates, the current value andmemory address are compared with the value and memory address recordedin the latest one of the created snapshots.

Based on the detection result of step 708, step 710 of process 700determines if both the value of the candidate and the memory address forthe value of the candidate are not updated. If any one of the value andthe memory address is updated (NO in step 710), a snapshot is createdfor the candidate in step 712. In cases where both the value and thememory address are not updated (YES in step 710), the process 700proceeds to step 714 to determine whether all the target variables andexpressions are detected. If not, the process 700 returns to step 706 tocontinue detecting updates of the remaining target variables andexpressions. If detections of all the target variables and expressionsare performed, the process 700 returns to step 704 to execute the nextstatement of the code snippet until all the statements included in thecode snippet are executed.

FIG. 8 shows a block diagram of a system 800 for monitoring updates ofvariables and expressions in accordance with embodiments of the presentinvention. As shown in FIG. 8, code 802 (to be debugged) is input to thesystem 800. A debugger 804 suitable for debugging the code 802 isconnected to the system 800. The system 800 includes a user interface810 having a code snippet selector 812, a variable/expression selector814, and a variable/expression monitor 816. The user interface 810allows a user to specify monitor points, variables and/or expressions tobe monitored. The user interface 810 is also used to present thedebugging results to the user. The code snippet selector 812 in the userinterface 810 is configured to present the code 802 for the user andreceive user selection of monitor points in the code. The code snippetselector 812 may allow the user to set more than two monitor points insome embodiments to specify multiple code snippets to be debugged.Information of the monitor points may be transmitted to thevariable/expression extractor 820. The information of the monitor pointsmay include code line numbers, function names, class names, and otherinformation used to identify the monitor points from the code 802.

The variable/expression extractor 820 is configured to parse a codesnippet of the code 802 between the specified two monitor points so asto collect variables included in the code snippet. Thevariable/expression extractor 820 is also configured to parse thedebugger 804 so as to collect expressions defined in the debugger 804.The collected variables and expressions may be provided by thevariable/expression extractor 820 to the variable/expression selector814 for display. The user may select one or more variables andexpressions to be monitored from the displayed variables andexpressions. The selected variables and expressions are communicatedback to the variable/expression extractor 820.

The system 800 also includes a snapshot collector 830 configured tomonitor the variables and expressions and record snapshots for thevariables and expressions by executing the code snippet. The snapshotcollector 830 obtains the variables and expressions to be monitored fromthe variable/expression extractor 820. In some embodiments, in order toidentify a variable from the code 802, some information such as the nameof the variable, the position of declaration of the variable, and thelike may also be received from the variable/expression extractor 820.The snapshot collector 830 may execute the code snippet of the code 802using the debugger 804. The snapshot collector 830 may also monitorupdates of the variables and expressions to be monitored so as to createsnapshots for those variables and expressions. The monitoring process800 illustrated with reference to FIG. 6 may be performed in thesnapshot collector 830.

An example structure of the snapshot collector 830 is shown in FIG. 9.The snapshot collector 830 includes a collector controller 831configured to control the operations of the snapshot collector 830. Thesnapshot collector 830 also includes a code debugging module 832configured to execute the code snippet of the code 802 so as to monitorupdates of the variables and expressions. In order to facilitateexecution of code snippets written in different programming languages,the debugger 804 may include debuggers 804 ₁, 804 ₂ . . . 804 _(K) thatare suitable for debugging code snippets written in K differentprogramming languages. The snapshot collector 830 may include multipledebugger adapters 833 ₁, 833 ₂ . . . 833 _(K). Each of the debuggeradapters 833 ₁ to 833 _(K) is configured to adapt one of debuggers 804 ₁to 804 _(K) to the code debugging module 832. The collector controller831 may control which of the debuggers 804 ₁ to 804 _(K) can be utilizedbased on the programming language of the input code 802.

Referring back to FIG. 8, during operation of the snapshot collector830, each time a snapshot for a variable or an expression is created,the snapshot collector 830 may provide the created snapshot for thevariable/expression monitor 816 included in the user interface 810. Thevariable/expression monitor 816 may display the snapshot obtained fromthe snapshot collector 830 so that the updates of the variables andexpressions can be observed by the user in time.

The system 800 also includes a report generator 840. After the snapshotcollector 830 finishes the monitoring process, all the snapshots for thevariables and expressions collected by the snapshot collector 830 may betransmitted to the report generator 840. The report generator 840arranges the recorded snapshots for each of the variables andexpressions and then generates a report that can assist the user toanalyze the debugging result of the code snippet. The report generator840 may arrange the snapshots recorded for a variable or expression in asequence based on the timestamps included in the respective snapshots.As shown in FIG. 10, each of the variables VAR1 to VAR_(N) has asnapshot list 1010 ₁ . . . 1010 _(N). The snapshots are arranged in atime order based on when the snapshots are created. Each of theexpressions EXPR1 to EXPR_(M) has also an associated snapshot list 1020₁ . . . 1020 _(M). A snapshot for a variable or expression may includethe value of the variable or expression 1001, the memory address for thevalue 1002, and context information 1003. In some other embodiments, thereport generator 840 may alternatively or additionally generate adiagram or a curve to represent a change flow for a variable or anexpression, such as a change flow in the value or memory address of thevariable or the expression. The generated report of the snapshots isprovided to the variable/expression monitor 816 to be displayed for theuser.

In cases where multiple code snippets are specified by the user, foreach of the code snippets, the system 800 may operate to generatesnapshots for variables to be monitored in the code snippet and forexpressions to be monitored in the debugger 804. Corresponding snapshotsmay be created and displayed to the user respectively so as to allow theuser to analyze whether the respective code snippets are executed asexpected.

The present invention may be a system, an apparatus, a device, a method,and/or a computer program product. The computer program product mayinclude a computer readable storage medium (or media) having computerreadable program instructions thereon for causing a processor to carryout aspects of the present invention.

The computer readable storage medium can be a tangible device that canretain and store instructions for use by an instruction executiondevice. The computer readable storage medium may be, for example, but isnot limited to, an electronic storage device, a magnetic storage device,an optical storage device, an electromagnetic storage device, asemiconductor storage device, or any suitable combination of theforegoing. A non-exhaustive list of more specific examples of thecomputer readable storage medium includes the following: a portablecomputer diskette, a hard disk, a random access memory (RAM), aread-only memory (ROM), an erasable programmable read-only memory (EPROMor Flash memory), a static random access memory (SRAM), a portablecompact disc read-only memory (CD-ROM), a digital versatile disk (DVD),a memory stick, a floppy disk, a mechanically encoded device such aspunch-cards or raised structures in a groove having instructionsrecorded thereon, and any suitable combination of the foregoing. Acomputer readable storage medium, as used herein, is not to be construedas being transitory signals per se, such as radio waves or other freelypropagating electromagnetic waves, electromagnetic waves propagatingthrough a waveguide or other transmission media (for example, lightpulses passing through a fiber-optic cable), or electrical signalstransmitted through a wire.

Computer readable program instructions described herein can bedownloaded to respective computing/processing devices from a computerreadable storage medium or to an external computer or external storagedevice via a network, for example, the Internet, a local area network, awide area network and/or a wireless network. The network may comprisecopper transmission cables, optical transmission fibers, wirelesstransmission, routers, firewalls, switches, gateway computers and/oredge servers. A network adapter card or network interface in eachcomputing/processing device receives computer readable programinstructions from the network and forwards the computer readable programinstructions for storage in a computer readable storage medium withinthe respective computing/processing device.

Computer readable program instructions for carrying out operations ofthe present invention may be assembler instructions,instruction-set-architecture (ISA) instructions, machine instructions,machine dependent instructions, microcode, firmware instructions,state-setting data, or either source code or object code written in anycombination of one or more programming languages, including an objectoriented programming language such as Smalltalk, C++ or the like, andconventional procedural programming languages, such as the “C”programming language or similar programming languages. The computerreadable program instructions may execute entirely on the user'scomputer, partly on the user's computer, as a stand-alone softwarepackage, partly on the user's computer and partly on a remote computeror entirely on the remote computer or server. In the latter scenario,the remote computer may be connected to the user's computer through anytype of network, including a local area network (LAN) or a wide areanetwork (WAN), or the connection may be made to an external computer(for example, through the Internet using an Internet Service Provider).In some embodiments, electronic circuitry including, for example,programmable logic circuitry, field-programmable gate arrays (FPGA), orprogrammable logic arrays (PLA) may execute the computer readableprogram instructions by utilizing state information of the computerreadable program instructions to personalize the electronic circuitry,in order to perform aspects of the present invention.

Aspects of the present invention are described herein with reference toflowchart illustrations and/or block diagrams of methods, apparatus(systems), and computer program products according to embodiments of theinvention. It will be understood that each block of the flowchartillustrations and/or block diagrams, and combinations of blocks in theflowchart illustrations and/or block diagrams, can be implemented bycomputer readable program instructions.

These computer readable program instructions may be provided to aprocessor of a general purpose computer, special purpose computer, orother programmable data processing apparatus to produce a machine, suchthat the instructions, which execute via the processor of the computeror other programmable data processing apparatus, create means forimplementing the functions/acts specified in the flowchart and/or blockdiagram block or blocks. These computer readable program instructionsmay also be stored in a computer readable storage medium that can directa computer, a programmable data processing apparatus, and/or otherdevices to function in a particular manner, such that the computerreadable storage medium having instructions stored therein comprises anarticle of manufacture including instructions which implement aspects ofthe function/act specified in the flowchart and/or block diagram blockor blocks.

The computer readable program instructions may also be loaded onto acomputer, other programmable data processing apparatus, or other deviceto cause a series of operational steps to be performed on the computer,other programmable apparatus or other device to produce a computerimplemented process, such that the instructions which execute on thecomputer, other programmable apparatus, or other device implement thefunctions/acts specified in the flowchart and/or block diagram block orblocks.

The flowchart and block diagrams illustrate the architecture,functionality, and operation of possible implementations of systems,methods and computer program products according to various embodimentsof the present invention. In this regard, each block in the flowchart orblock diagrams may represent a module, snippet, or portion of code,which comprises one or more executable instructions for implementing thespecified logical function(s). It should also be noted that, in somealternative implementations, the functions noted in the block may occurout of the order noted in the figures. For example, two blocks shown insuccession may, in fact, be executed substantially concurrently, or theblocks may sometimes be executed in the reverse order, depending uponthe functionality involved. It will also be noted that each block of theblock diagrams and/or flowchart illustration, and combinations of blocksin the block diagrams and/or flowchart illustration, can be implementedby special purpose hardware-based systems that perform the specifiedfunctions or acts, or combinations of special purpose hardware andcomputer instructions.

The descriptions of the various embodiments of the present inventionhave been presented for purposes of illustration, but are not intendedto be exhaustive or limited to the embodiments disclosed. Manymodifications and variations will be apparent to those of ordinary skillin the art without departing from the scope and spirit of the describedembodiments. The terminology used herein was chosen to best explain theprinciples of the embodiments, the practical application or technicalimprovement over technologies found in the marketplace, or to enableothers of ordinary skill in the art to understand the embodimentsdisclosed herein.

What is claimed is:
 1. A system comprising: one or more processors; amemory coupled to at least one of the one or more processors; and a setof computer program instructions stored in the memory, with the set ofcomputer program instructions including instructions programmed to causethe one or more processors to perform the following actions: receiving aset of target code including a code snippet specified by a developer,parsing, by machine logic, the code snippet to determine a raw set ofvariable(s) and/or expression(s) that are present in the code snippet,receiving, by machine logic, user input indicative of a selected set ofvariable(s) and/or expression(s) from the raw set of variable(s) and/orexpression(s), executing the set of target code for debugging purposes,during execution of the set of target code, monitoring, by machinelogic, the selected set of variable(s) and/or expressions(s) to detectto a set of memory location updates made to the set of variable(s)and/or expression(s), with each memory location update reflecting achange in memory location where a variable or expression is storedwithout a change in the value of the variable or expression, duringexecution of the set of target code and for each detected given memorylocation update of a given selected variable and/or expression of theset of variable(s) and/or expression(s), creating a contemporaneoussnapshot with each snapshot including: (i) a memory address of the givenselected variable and/or expression, and (ii) context data indicative ofenvironment/condition related information at the time of the detectedgiven memory location update, with the context data including: (a) arelationship of function calls related to the set of variable(s) and/orexpression(s), and (b) a timestamp including information indicative of acreation time for the contemporaneous snapshot, and generating a memorychange snapshot sequence report, with the memory change snapshotsequence report including, for each given selected variable and/orexpression, a sequence of contemporaneous snapshots corresponding todetected given memory location updates, with the sequence of thecontemporaneous snapshots based on the timestamps corresponding to thecontemporaneous snapshots that correspond to a given selected variableand/or expression.
 2. The system of claim 1, wherein the memory changesnapshot sequence report further includes: for each given selectedvariable and/or expression, a diagram representative of a change flowfor the memory address of the given selected variable and/or expressionthroughout the sequence of contemporaneous snapshots.
 3. The system ofclaim 1, wherein each created snapshot further includes a timestampindicating when the snapshot was created.
 4. The system of claim 1wherein each created snapshot further includes a statement containing adeclaration of the memory location of the updated variable orexpression.
 5. The system of claim 1, wherein each created snapshotfurther includes an identity of a statement in the code snippet thatcaused the memory location update corresponding to the snapshot.
 6. Thesystem of claim 1, wherein each created snapshot further includes astack status of the variable or expression subject to the memorylocation update corresponding to the snapshot.
 7. A computer programproduct comprising: a memory coupled to at least one of one or moreprocessors; and a set of computer program instructions stored in thememory, with the set of computer program instructions includinginstructions programmed to cause the one or more processors to performthe following actions: receiving a set of target code including a codesnippet specified by a developer, parsing, by machine logic, the codesnippet to determine a raw set of variable(s) and/or expression(s) thatare present in the code snippet, receiving, by machine logic, user inputindicative of a selected set of variable(s) and/or expression(s) fromthe raw set of variable(s) and/or expression(s), executing the set oftarget code for debugging purposes, during execution of the set oftarget code, monitoring, by machine logic, the selected set ofvariable(s) and/or expressions(s) to detect to a set of memory locationupdates made to the set of variable(s) and/or expression(s), with eachmemory location update reflecting a change in memory location where avariable or expression is stored without a change in the value of thevariable or expression, during execution of the set of target code andfor each detected given memory location update of a given selectedvariable and/or expression of the set of variable(s) and/orexpression(s), creating a contemporaneous snapshot with each snapshotincluding: (i) a memory address of the given selected variable and/orexpression, and (ii) context data indicative of environment/conditionrelated information at the time of the detected given memory locationupdate, with the context data including: (a) a relationship of functioncalls related to the set of variable(s) and/or expression(s), and (b) atimestamp including information indicative of a creation time for thecontemporaneous snapshot, and generating a memory change snapshotsequence report, with the memory change snapshot sequence reportincluding, for each given selected variable and/or expression, asequence of contemporaneous snapshots corresponding to detected givenmemory location updates, with the sequence of the contemporaneoussnapshots based on the timestamps corresponding to the contemporaneoussnapshots that correspond to a given selected variable and/orexpression.
 8. The computer program product of claim 7, wherein thememory change snapshot sequence report further includes: for each givenselected variable and/or expression, a diagram representative of achange flow for the memory address of the given selected variable and/orexpression throughout the sequence of contemporaneous snapshots.
 9. Thecomputer program product of claim 7, wherein each created snapshotfurther includes a timestamp indicating when the snapshot was created.10. The computer program product of claim 7 wherein each createdsnapshot further includes a statement containing a declaration of thememory location of the updated variable or expression.
 11. The computerprogram product of claim 7, wherein each created snapshot furtherincludes an identity of a statement in the code snippet that caused thememory location update corresponding to the snapshot.
 12. The computerprogram product of claim 7, wherein each created snapshot furtherincludes a stack status of the variable or expression subject to thememory location update corresponding to the snapshot.
 13. The system ofclaim 1 wherein the set of computer program instructions further includeinstructions for causing the one or more processors to perform thefollowing actions: determining a programming language of the codesnippet; and selecting a debugger from a plurality of debuggers based,at least in part on the determined programming language.
 14. The systemof claim 13 wherein the execution of the set of target code is performedby the selected debugger.
 15. The computer program product of claim 7wherein the set of computer program instructions further includeinstructions for causing the one or more processors to perform thefollowing actions: determining a programming language of the codesnippet; and selecting a debugger from a plurality of debuggers based,at least in part on the determined programming language.
 16. Thecomputer program product of claim 15 wherein the execution of the set oftarget code is performed by the selected debugger.